public class ThreadDemo08 {
    public static void main(String[] args) throws InterruptedException {
        Person person = new Person();

        MyThread04 myThread04 = new MyThread04(person, true);
        myThread04.start();

        Thread.sleep(1000);
        System.out.println("HAHA");

        MyThread04 myThread05 = new MyThread04(person, false);
        myThread05.start();

    }
}


class MyThread04 extends Thread {
    private Person person;
    private boolean flag;

    public MyThread04(Person person, boolean flag) {
        this.person = person;
        this.flag = flag;
    }

    @Override
    public void run() {
        if (flag) {
            person.eat();
        } else {
            person.say();
        }
    }
}

class Person {

    public synchronized void eat() {
        System.out.println("吃");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void say() {
        System.out.println("说");
    }
}
